package com.chentf.reggie.controller;

import com.chentf.reggie.schedule.ScheduleTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chentengfei
 * @desc 定时任务(动态修改定时任务执行时间)
 * @date 2022-09-25 19:25:53
 */
@Slf4j
@RestController
@RequestMapping("schedul")
public class SchedulController {

    private final ScheduleTask scheduleTask;

    public SchedulController(ScheduleTask scheduleTask) {
        this.scheduleTask = scheduleTask;
    }

    @GetMapping("updateCron")
    public String updateCron(String cron){
        log.info("new cron:{}",cron);
        scheduleTask.setCron(cron);
        return "ok";
    }

    @GetMapping("/updateTime")
    public String updateTime(Long timer){
        log.info("new timer:{}",timer);
        scheduleTask.setTimer(timer);
        return "ok";
    }
}
